unsigned char CRC8(unsigned char *puchMsg, unsigned char length)
{
    unsigned char i;
    unsigned char crc = 0;        // Initial value
    while(length--)
    {
        crc ^= *puchMsg++;        // crc ^= *puchMsg; puchMsg++;
        for ( i = 0; i < 8; i++ )
        {
            if ( crc & 0x80 )
                crc = (crc << 1) ^ 0x07;
            else
                crc <<= 1;
        }
    }
    return crc;
}
